<!--商品货源详情界面组件-->
<template>
    <div class="goods-box">
        <div class="search2">
            <div style="display: flex;height: 35px;line-height: 35px;">
                <el-input v-model="searchKeys" maxlength="100" clearable style="width:290px;" />
                <img src="@/assets/img/search.png" @click="handleSearch" class="search-icon" />
            </div>
            <i style="color:#696969;font-size:13px;font-style:normal;">
                &nbsp;热门搜索：
                <a class="tag-item" @click="handleTopicDetail('苹果')">苹果</a>
                <a class="tag-item" @click="handleTopicDetail('新疆哈密瓜')">新疆哈密瓜</a>
                <a class="tag-item" @click="handleTopicDetail('樱桃')">樱桃</a>
                <a class="tag-item" @click="handleTopicDetail('西红柿')">西红柿</a>
                <a class="tag-item" @click="handleTopicDetail('水稻')">水稻</a>
                <a class="tag-item" @click="handleTopicDetail('玉米')">玉米</a>
                <a class="tag-item" @click="handleTopicDetail('赣南脐橙')">赣南脐橙</a>
            </i>
            <el-button v-show="searchKeys != ''" style="width: 80px;height:35px;line-height: 35px;margin-left: 10px;"
                @click="backHandle">
                <el-icon>
                    <Close />
                </el-icon>取 消
            </el-button>
        </div>
        <div class="goods" v-for="(item, index) in cgoods" :key="index" @click="detailsClick(item.orderId)"
            :style="(index + 1) % 5 === 0 ? 'margin-right:0' : 'margin-right:25px;'">
            <img class="goods-img" v-if="item.picture != ''" :src="item.picture" alt="图片为获取1" />
            <div class="info">
                <span class="initiator">[{{ item.ownName }}]</span>
                <p class="content">{{ item.content }}</p>
                <span class="price" v-if="item.price">￥{{ item.price }}</span>
            </div>
        </div>
    </div>
</template>


<script setup>
import { defineProps, ref } from 'vue';
import router from '@/router'
import { defineEmits } from 'vue';

const emit = defineEmits(['handleSearch','refresh']);

// 接收父组件传过来的数据
const props = defineProps({
    cgoods: {
        type: Array,
    }
})

//格式化时间
const time = (value) => {
    let date = new Date(value);
    let y = date.getFullYear();
    let MM = date.getMonth() + 1;
    MM = MM < 10 ? "0" + MM : MM;
    let d = date.getDate();
    d = d < 10 ? "0" + d : d;
    let h = date.getHours();
    h = h < 10 ? "0" + h : h;
    let m = date.getMinutes();
    m = m < 10 ? "0" + m : m;
    let s = date.getSeconds();
    s = s < 10 ? "0" + s : s;
    return y + "-" + MM + "-" + d + " " + h + ":" + m;
}


//搜索
const searchKeys = ref('');

const handleSearch = () => {
    emit('handleSearch', searchKeys.value)
}

//关键字搜索
const handleTopicDetail = (val) => {
    searchKeys.value = val
    handleSearch()
}

//返回
const backHandle = () => {
    searchKeys.value = ''
    //调用父类的方法
    emit('refresh')
}

//详情
const detailsClick = (item) => {
    router.push(`/index/good_details?orderId=${item}`).catch((err) => err);
}


</script>

<style lang="scss" scoped>
.search2 {
    width: 100%;
    height: 80px;
    background-color: white;
    padding: 10px 20px;
    line-height: 80px;
    display: flex;
    align-items: center;

    .tag-item {
        margin-right: 10px;
        cursor: pointer;
        color: blue;
    }

    .search-icon {
        position: relative;
        left: -2px;
        cursor: pointer;
    }
}

.goods-box {
    background-color: #f9f9f9;
    width: 1100px;
    margin: 10px auto;

    .goods {
        float: left;
        width: 200px;
        height: 290px;
        margin-top: 15px;
        padding: 15px;
        background-color: white;
        border: 1px solid #d3d3d3;
        text-align: left;
        cursor: pointer;

        .goods-img {
            float: left;
            width: 170px;
            height: 170px;
            margin-right: 10px;
            border-radius: 6px;
        }

        .info {
            width: 160px;
            float: left;

            .initiator {
                color: #666;
            }

            .title {
                /*超出的部分隐藏*/
                overflow: hidden;
                /*文字用省略号替代超出的部分*/
                text-overflow: ellipsis;
                /*弹性伸缩盒子模型显示*/
                display: -webkit-box;
                /*限制在一个块元素显示文本的行数*/
                -webkit-line-clamp: 1;
                /*设置或检索伸缩盒对象的子元素排列方式*/
                -webkit-box-orient: vertical;
            }

            .content {
                height: 50px;
                /*超出的部分隐藏*/
                overflow: hidden;
                /*文字用省略号替代超出的部分*/
                text-overflow: ellipsis;
                /*弹性伸缩盒子模型显示*/
                display: -webkit-box;
                /*限制在一个块元素显示文本的行数*/
                -webkit-line-clamp: 7;
                /*设置或检索伸缩盒对象的子元素排列方式*/
                -webkit-box-orient: vertical;
                font-size: 10px;
            }

            .price {
                font-size: 18px;
                font-weight: bold;
                display: block;
                color: red;
            }
        }
    }
}

.search2 .el-input--suffix .el-input__inner {
    height: 35px;
    line-height: 35px;
}
</style>